package jannex.sql.extensions;

import jannex.Jannex;
import jannex.internal.ExceptionFactory;
import jannex.sql.JxClob;

import java.io.InputStream;
import java.io.OutputStream;
import java.io.Reader;
import java.io.Writer;
import java.sql.Clob;
import java.sql.SQLException;

public class ClobImpl implements JxClob {

    private Clob clob;
    private Jannex jannex;

    public ClobImpl(Clob clob, Jannex jannex) {
        this.clob = clob;
        this.jannex = jannex;
    }

    @Override
    public long length() {
        try {
            return clob.length();
        } catch (SQLException e) {
            throw ExceptionFactory.make(e);
        }
    }

    @Override
    public String getSubString(long pos, int length) {
        try {
            return clob.getSubString(pos, length);
        } catch (SQLException e) {
            throw ExceptionFactory.make(e);
        }
    }

    @Override
    public Reader getCharacterStream() {
        try {
            return clob.getCharacterStream();
        } catch (SQLException e) {
            throw ExceptionFactory.make(e);
        }
    }

    @Override
    public InputStream getAsciiStream() {
        try {
            return clob.getAsciiStream();
        } catch (SQLException e) {
            throw ExceptionFactory.make(e);
        }
    }

    @Override
    public long position(String searchstr, long start) {
        try {
            return clob.position(searchstr, start);
        } catch (SQLException e) {
            throw ExceptionFactory.make(e);
        }
    }

    @Override
    public long position(Clob searchstr, long start) {
        try {
            return clob.position(searchstr, start);
        } catch (SQLException e) {
            throw ExceptionFactory.make(e);
        }
    }

    @Override
    public int setString(long pos, String str) {
        try {
            return clob.setString(pos, str);
        } catch (SQLException e) {
            throw ExceptionFactory.make(e);
        }
    }

    @Override
    public int setString(long pos, String str, int offset, int len) {
        try {
            return clob.setString(pos, str, offset, len);
        } catch (SQLException e) {
            throw ExceptionFactory.make(e);
        }
    }

    @Override
    public OutputStream setAsciiStream(long pos) {
        try {
            return clob.setAsciiStream(pos);
        } catch (SQLException e) {
            throw ExceptionFactory.make(e);
        }
    }

    @Override
    public Writer setCharacterStream(long pos) {
        try {
            return clob.setCharacterStream(pos);
        } catch (SQLException e) {
            throw ExceptionFactory.make(e);
        }
    }

    @Override
    public void truncate(long len) {
        try {
            clob.truncate(len);
        } catch (SQLException e) {
            throw ExceptionFactory.make(e);
        }
    }

    @Override
    public void free() {
        try {
            clob.free();
        } catch (SQLException e) {
            throw ExceptionFactory.make(e);
        }
    }

    @Override
    public Reader getCharacterStream(long pos, long length) {
        try {
            return clob.getCharacterStream(pos, length);
        } catch (SQLException e) {
            throw ExceptionFactory.make(e);
        }
    }
}
